package com.mobi.Survey.uicomponents;

import android.content.Context;
import android.view.Gravity;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.mobi.Survey.controller.SurveyDetailPojo;
import com.mobi.Survey.utils.Device;

/**
 * 
 * <p>
 * <b>Author:</b> Yahya Arshad
 * <p>
 * <b>Company:</b> Mobi Media Soft
 * <p>
 * <b> Website:</b> www.mobimediasoft.com
 * <p>
 * CustomImageView.java
 * 
 * 
 */
public class CustomImageView extends ImageView
{
	private LinearLayout ll;
	private Context ctx;

	public CustomImageView(Context context, SurveyDetailPojo sdp)
	{
		super(context);
		this.ctx = context;
		ll = new LinearLayout(ctx);

		ll.setOrientation(LinearLayout.VERTICAL);

		if (sdp.getControlText() != null && sdp.getControlText().length() > 0)
		{
			CustomTextView txt = new CustomTextView(ctx);
			txt.setCustomColor(sdp);
			txt.setText(sdp.getControlText());
			ll.addView(txt);

		}

		LinearLayout.LayoutParams param = null;
		if (sdp.getPercentHeight() > 0 && sdp.getPercentWidth() > 0)
		{
			int height = Device.getInstance().getPercentHeight(
					sdp.getPercentHeight() / 100f);
			int width = Device.getInstance().getPercentWidth(
					sdp.getPercentWidth() / 100f);
			param = new LinearLayout.LayoutParams(width, height);

			this.setAdjustViewBounds(true);
			this.setScaleType(ImageView.ScaleType.FIT_XY);
		} else
		{
			int width = Device.getInstance().getPercentWidth(0.8f);
			this.setScaleType(ImageView.ScaleType.FIT_XY);
			param = new LinearLayout.LayoutParams(width, width);
		}

		ll.addView(this);

		this.setLayoutParams(param);
		param.gravity = Gravity.CENTER;

	}

	public View getView()
	{
		return ll;
	}

}
